package koala.kuangjiademo.data;


import com.google.gson.annotations.SerializedName;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class DeviceModel implements Serializable, MenuGetter {
    public int id;
    @SerializedName("prodmodel")
    public String name;
    @SerializedName("prodspec")
    public String type;

    @Override
    public String getMenuItem() {
        return name;
    }

    public static class Data implements Serializable {
        List<DeviceModel> records;
        private List<String> types;
        private int simCardModelId = -1;

        public List<String> getTypes() {
            if (types != null) return types;
            types = new ArrayList<>();
            for (DeviceModel record : records) {
                if (record.type.equals("卡")) {
                    simCardModelId = record.id;
                } else if (!types.contains(record.type)) {
                    types.add(record.type);
                }
            }
            return types;
        }

        public List<DeviceModel> getModelsByType(String type) {
            List<DeviceModel> names = new ArrayList<>();
            for (DeviceModel record : records) {
                if (record.type.equals(type)) {
                    names.add(record);
                }
            }
            return names;
        }

        public int getSimCardModelId() {
            if (simCardModelId == -1) getTypes();
            return simCardModelId;
        }

        public DeviceModel getDeviceModelById(int modelId) {
            for (DeviceModel record : records) {
                if (record.id == modelId) return record;
            }
            return null;
        }
    }

    public static class Response extends ResponsePacket<Data> {

    }
}
